package com.bipbip.repositorio;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.bipbip.modelo.ModeloVehiculo;

@Repository(value = "modeloDao")
@Transactional(readOnly = true)
public class JPAModeloDAOImpl implements ModeloDAO {

	private EntityManager em = null;

	/*
	 * Sets the entity manager.
	 */
	@PersistenceContext
	public void setEntityManager(EntityManager em) {
		this.em = em;
	}

	public ModeloVehiculo select(int id) {
		return em.find(ModeloVehiculo.class, id);
	}

	public List<ModeloVehiculo> selectAll() {
		return em.createQuery("select m from ModeloVehiculo m").getResultList();
	}

	public List<ModeloVehiculo> selectBy(String attr, Integer value) {
		return em.createQuery("select m from ModeloVehiculo m where " + attr + "=" + value).getResultList();
	}
}
